﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace project_web2
{

    public class DAL: System.Web.UI.Page
    {
        SqlConnection sqlcnn;
        string conn = ConfigurationManager.ConnectionStrings["connec"].ConnectionString;
        public DAL()
        {
            sqlcnn = new SqlConnection(conn);
        }
        public  DataTable get_data(string sql, bool stt = true)
        {
            SqlDataAdapter da = new SqlDataAdapter(sql, sqlcnn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataTable dt = ds.Tables[0];
            if (stt) {
                 DataColumn STT = new DataColumn("SoTT");
                dt.Columns.Add(STT);
                int i = 1;
                foreach (DataRow row in dt.Rows)
                {
                    row[STT] = i;
                    i++;
                }
            }

            return dt;
        }
        public void executeQuery(string sql)
        {
            sqlcnn.Open();
            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandText = sql;
            sqlcmd.CommandType = CommandType.Text;
            sqlcmd.Connection = sqlcnn;
            sqlcmd.ExecuteNonQuery();
            sqlcnn.Close();
        }
        public int int_executeQuery(string sql)
        {
            sqlcnn.Open();
            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandText = sql;
            sqlcmd.CommandType = CommandType.Text;
            sqlcmd.Connection = sqlcnn;
            int kq=(int)sqlcmd.ExecuteScalar();
            sqlcnn.Close();
            return kq;
        }
    }
}
